package com.wz.project.stock.viewStock.controller;

import java.util.List;

import com.wz.project.stock.viewStock.domain.ViewStockPk;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.wz.framework.aspectj.lang.annotation.Log;
import com.wz.framework.aspectj.lang.enums.BusinessType;
import com.wz.project.stock.viewStock.domain.ViewStock;
import com.wz.project.stock.viewStock.service.IViewStockService;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.common.utils.poi.ExcelUtil;
import com.wz.framework.web.page.TableDataInfo;

/**
 * 子库存查询Controller
 * 
 * @author wz
 * @date 2022-12-01
 */
@Controller
@RequestMapping("/stock/viewStock")
public class ViewStockController extends BaseController
{
    private String prefix = "stock/viewStock";

    @Autowired
    private IViewStockService viewStockService;

    @RequiresPermissions("stock:viewStock:view")
    @GetMapping()
    public String viewStock()
    {
        return prefix + "/viewStock";
    }
//    @RequiresPermissions("stock:viewStock:view")
//    @GetMapping()
//    public String viewStockPk()
//    {
//        return prefix + "/viewStockPk";
//    }
    /**
     * 查询子库存查询列表
     */
//    @RequiresPermissions("stock:viewStock:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ViewStock viewStock)
    {
        startPage();
        List<ViewStock> list = viewStockService.selectViewStockList(viewStock);
        return getDataTable(list);
    }
//    @RequiresPermissions("stock:viewStock:list")
    @PostMapping("/listPk")
    @ResponseBody
    public TableDataInfo listPk(ViewStockPk viewStock)
    {
        startPage();
        List<ViewStockPk> list = viewStockService.selectViewStockListPk(viewStock);
        return getDataTable(list);
    }
    /**
     * 导出子库存查询列表
     */
    @RequiresPermissions("stock:viewStock:export")
    @Log(title = "子库存查询", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ViewStock viewStock)
    {
        List<ViewStock> list = viewStockService.selectViewStockList(viewStock);
        ExcelUtil<ViewStock> util = new ExcelUtil<ViewStock>(ViewStock.class);
        return util.exportExcel(list, "viewStock");
    }

    /**
     * 新增子库存查询
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存子库存查询
     */
    @RequiresPermissions("stock:viewStock:add")
    @Log(title = "子库存查询", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ViewStock viewStock)
    {
        return toAjax(viewStockService.insertViewStock(viewStock));
    }

    /**
     * 修改子库存查询
     */
    @GetMapping("/edit/{stockId}")
    public String edit(@PathVariable("stockId") String stockId, ModelMap mmap)
    {
        ViewStock viewStock = viewStockService.selectViewStockById(stockId);
        mmap.put("viewStock", viewStock);
        return prefix + "/edit";
    }

    /**
     * 修改保存子库存查询
     */
    @RequiresPermissions("stock:viewStock:edit")
    @Log(title = "子库存查询", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ViewStock viewStock)
    {
        return toAjax(viewStockService.updateViewStock(viewStock));
    }

    /**
     * 删除子库存查询
     */
    @RequiresPermissions("stock:viewStock:remove")
    @Log(title = "子库存查询", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(viewStockService.deleteViewStockByIds(ids));
    }
}
